<?php

class allocations extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('allocationsmodel');
    }

    public function addallocation()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');

        $this->form_validation->set_rules('serial_id', 'serial_id', 'required');
        $this->form_validation->set_rules('id', 'id', 'required');
        $this->form_validation->set_rules('employee_id', 'employee_id', 'required');
        $this->form_validation->set_rules('allocation_date', 'allocation_date', 'required');
        $this->form_validation->set_rules('allocation_status', 'allocation_status', 'required');
        $this->form_validation->set_rules('region', 'region', 'required');
        $this->form_validation->set_rules('location', 'location', 'required');
        

        if ($this->form_validation->run() === FALSE) {
            $this->load->view('allocations/addallocation');

        } else {
            $this->allocationsmodel->addallocation();
            $this->load->view('allocations/addsuccess');

        }

    }

    public function getallocation()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('serial_id', 'serial_id', 'required');

        if ($this->form_validation->run() === FALSE) {
            $this->load->view('allocations/editallocation');
        }
            else
            {
                $data['datareceived']=$this->allocationsmodel->getData();
                $this->load->view('allocations/edit',$data);

            }
    }

    public function updateallocation()
    {
        $this->allocationsmodel->updateData();
        $this->load->view('allocations/updatesuccess');

    }

    public function view()
    {
        $data['allocations'] = $this->allocationsmodel->view();
        $this->load->view('allocations/view', $data);
    }
}

?>